import { Suspense,lazy } from 'react'
import {Navigate } from 'react-router-dom'
import Loading from '../components/loading'
const RouterSrc = (props:{href:string}) => {
    const power = JSON.parse(sessionStorage.getItem('power') || '{}');
    //是否有权限
    let isPower = false;
    let Com:React.LazyExoticComponent<React.ComponentType<any>> | null=null;
    if(power){
        for (let i = 0; i < power.length; i++) {
            if (power[i].src === props.href) {
                isPower = true;
                Com=lazy(()=>import(`../pages${props.href}`))
            }
        }
    }
    //Suspense  因为是异步加载  在还没有加载出来的时候执行的组件
    if (isPower && Com!=null) {
        return <Suspense fallback={<Loading />}>
            <Com/>
        </Suspense>
    }else{
        return <Navigate to="/login"/>
    }
}
export default RouterSrc;